package net.trustie.model;

import net.trustie.utils.DateHandler;
import net.trustie.utils.StringHandler;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.ExtractBy.Source;
import core.AfterExtractor;
import core.Page;
import core.ValidateExtractor;


@ExtractBy("//div[@id='wp']/div[@id='ct']/div[@id='postlist']")
public class lupaworld_Model implements AfterExtractor, ValidateExtractor {
	
	private String post_id = "";
	private String post_url = "";
	private String post_tags = "";
	private String extractTime = null;
	private String crawled_time = null;
	private int history = 0;
	
	
	@ExtractBy("//table[1]/tbody/tr/td[@class='vwthd']/h1[@class='ts']/span[@id='thread_subject']/text()")
	private String post_title;
	
	@ExtractBy("//div[1]/table[@class='plhin']/tbody/tr[1]/td[@class='plc']/div[@class='pct']/div[@class='pcb']/div[@class='t_fsz']/allText()")
	private String post_content;

	@ExtractBy(value = "//div[@id='wp']/div[@id='pt']/div[@class='z']/a[4]/text()", source = Source.RawHtml)
	private String post_type;
	
	@ExtractBy("//table[1]/tbody/tr/td[@class='pls']/div[@class='hm']/span[2]/text()")
	private int view_num;
	
	@ExtractBy("//table[1]/tbody/tr/td[@class='pls']/div[@class='hm']/span[5]/text()")
	private int reply_num;
	
	@ExtractBy("//div[1]/table[@class='plhin']/tbody/tr[2]/td[@class='plc']/div[@id='p_btn']/a[@id='recommend_add']/i/span[@id='recommendv_add']/text()")
	private int vote_up;
	
	@ExtractBy("//div[1]/table[@class='plhin']/tbody/tr[2]/td[@class='plc']/div[@id='p_btn']/a[@id='recommend_subtract']/i/span[@id='recommendv_subtract']/text()")
	private int vote_down;
	
	@ExtractBy("//div[1]/table[@class='plhin']/tbody/tr[1]/td[@class='plc']/div[@class='pi']/div[@class='pti']/div[@class='authi']/em[1]/text()")
	private String created_time;
	
	@ExtractBy("//div[1]/table[@class='plhin']/tbody/tr[1]/td[@class='pls']/div[@class='pls']/div[@class='pi']/div[@class='authi']/a/text()")
	private String author_name;
	
	@ExtractBy("//div[1]/table[@class='plhin']/tbody/tr[1]/td[@class='pls']/div[@class='pls']/div[@class='pi']/div[@class='authi']/a/@href")
	private String author_url;
	
	
	@Override
	public void afterProcess(Page page) {
		// TODO Auto-generated method stub
		String pageUrl = page.getPageUrl();
		post_url = pageUrl;		
		int lastIndex = pageUrl.lastIndexOf("/");
		String tmp = pageUrl.substring(lastIndex + 1);
		int index1 = tmp.indexOf("-");
		tmp = tmp.substring(index1 + 1);//****-*-*
		int index2 = tmp.indexOf("-");
		post_id = tmp.substring(0, index2);
		extractTime = DateHandler.getExtractTime();
		
		created_time = StringHandler.matchRightString(created_time, "\\d+-\\d+-\\d+ \\d+:\\d+:\\d+");
	}
	
	@Override
	public void validate(Page page) {
		// TODO Auto-generated method stub
		
	}

	public String getPost_id() {
		return post_id;
	}

	public void setPost_id(String post_id) {
		this.post_id = post_id;
	}

	public String getPost_url() {
		return post_url;
	}

	public void setPost_url(String post_url) {
		this.post_url = post_url;
	}

	public String getPost_tags() {
		return post_tags;
	}

	public void setPost_tags(String post_tags) {
		this.post_tags = post_tags;
	}

	public String getExtractTime() {
		return extractTime;
	}

	public void setExtractTime(String extractTime) {
		this.extractTime = extractTime;
	}

	public int getHistory() {
		return history;
	}

	public void setHistory(int history) {
		this.history = history;
	}

	public String getPost_title() {
		return post_title;
	}

	public void setPost_title(String post_title) {
		this.post_title = post_title;
	}

	public String getPost_content() {
		return post_content;
	}

	public void setPost_content(String post_content) {
		this.post_content = post_content;
	}

	public String getPost_type() {
		return post_type;
	}

	public void setPost_type(String post_type) {
		this.post_type = post_type;
	}

	public int getView_num() {
		return view_num;
	}

	public void setView_num(int view_num) {
		this.view_num = view_num;
	}

	public int getReply_num() {
		return reply_num;
	}

	public void setReply_num(int reply_num) {
		this.reply_num = reply_num;
	}

	public int getVote_up() {
		return vote_up;
	}

	public void setVote_up(int vote_up) {
		this.vote_up = vote_up;
	}

	public int getVote_down() {
		return vote_down;
	}

	public void setVote_down(int vote_down) {
		this.vote_down = vote_down;
	}

	public String getCreated_time() {
		return created_time;
	}

	public void setCreated_time(String created_time) {
		this.created_time = created_time;
	}

	public String getAuthor_name() {
		return author_name;
	}

	public void setAuthor_name(String author_name) {
		this.author_name = author_name;
	}

	public String getAuthor_url() {
		return author_url;
	}

	public void setAuthor_url(String author_url) {
		this.author_url = author_url;
	}

	public String getCrawled_time() {
		return crawled_time;
	}

	public void setCrawled_time(String crawled_time) {
		this.crawled_time = crawled_time;
	}

}
